//
//  HEMineServiceCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/10/16.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEMineServiceCell.h"

@interface HEMineServiceCell ()

@property (nonatomic, strong) UILabel *titleLb;

@property (nonatomic, strong) UIScrollView *manContent;

@end

@implementation HEMineServiceCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    // 标题
    _titleLb = [UILabel new];
    _titleLb.text = @"我的医养";
    [self.contentView addSubview:_titleLb];
    _titleLb.font = DYFont(21);
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
         make.left.equalTo(self.contentView).mas_offset(15);
         make.right.equalTo(self.contentView).mas_offset(-15);
     }];
    
    //
    _manContent = [[UIScrollView alloc] init];
    _manContent.scrollEnabled = YES;
    _manContent.showsVerticalScrollIndicator = NO;
    _manContent.showsHorizontalScrollIndicator = NO;
    [self.contentView addSubview:_manContent];

    [_manContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(10);
         make.left.equalTo(self.contentView).mas_offset(10);
         make.right.equalTo(self.contentView).mas_offset(-10);
         make.bottom.equalTo(self.contentView).mas_offset(-5);
     }];
    
       NSArray *manImgList = @[@{@"name":@"我的医生", @"icon":@"my_doctor"},
                               @{@"name":@"我的团队", @"icon":@"my_doctor"},
                                 @{@"name":@"问诊记录", @"icon":@"my_tw_icon"},
                               @{@"name":@"我的加号", @"icon":@"my_register"},

//                                 @{@"name":@"我的服务包", @"icon":@"my_service_pack"},
                               @{@"name":@"我的规划", @"icon":@"my_health_plan_icon"},
                               @{@"name":@"我的解读", @"icon":@"my_body_check"},
//                                 @{@"name":@"脊椎报告", @"icon":@"my_jk_report"},
//                                 @{@"name":@"试剂检测", @"icon":@"my_kit_report"}
       ];
        NSMutableArray *manArr = [NSMutableArray array];
            
        for (int i = 0; i < manImgList.count; i++) {
            
            NSDictionary *img = manImgList[i];

            // NSDictionary *img in manImgList
            QMUIButton *btn = [[QMUIButton alloc] init];
            btn.imagePosition = QMUIButtonImagePositionTop;// 将图片位置改为在文字下方
            btn.tintColorAdjustsTitleAndImage = UIColor.blackColor;
            btn.adjustsImageTintColorAutomatically = NO;
            btn.spacingBetweenImageAndTitle = 10;
            [btn setImage:UIImageMake(img[@"icon"]) forState:UIControlStateNormal];
            [btn setTitle:img[@"name"] forState:UIControlStateNormal];
            btn.titleLabel.font = DYFont(15);
            [_manContent addSubview:btn];
            btn.tag = i;

            [btn addTarget:self action:@selector(serverClick:) forControlEvents: UIControlEventTouchUpInside];

            [manArr addObject:btn];
            
            //
    //        [btn setupAutoSizeWithHorizontalPadding:10 buttonHeight:10];
        }
        
    // 实现masonry水平固定间隔方法
    [manArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:15 leadSpacing:0 tailSpacing:0];
    
    // 设置array的垂直方向的约束
    [manArr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_manContent).mas_offset(0);
    }];
     
    [_manContent setupAutoContentSizeWithRightView:manArr.lastObject rightMargin:0];
 }

- (void)serverClick:(QMUIButton *)sender {
    if ([_delegate respondsToSelector:@selector(mineServerDidSelectAtIndex:)]) {
        [_delegate mineServerDidSelectAtIndex:sender.tag];
    }
}

- (void)setModel:(UserInfo *)model {

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
